{% extends 'base.html' %}

{% block title %}AI生成故事 - AI故事生成系统{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-md-8 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h2 class="card-title mb-0">AI故事生成</h2>
                    <p class="text-muted mb-0">由 Moonshot AI 提供智能创作支持</p>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        
                        <div class="mb-3">
                            <label for="{{ form.title.id_for_label }}" class="form-label">故事标题</label>
                            {{ form.title }}
                            <div class="form-text">{{ form.title.help_text }}</div>
                            {% if form.title.errors %}
                            <div class="invalid-feedback d-block">
                                {{ form.title.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.category.id_for_label }}" class="form-label">故事类型</label>
                            {{ form.category }}
                            {% if form.category.errors %}
                            <div class="invalid-feedback d-block">
                                {{ form.category.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.keywords.id_for_label }}" class="form-label">关键词</label>
                            {{ form.keywords }}
                            <div class="form-text">输入故事相关的关键词，用空格分隔</div>
                            {% if form.keywords.errors %}
                            <div class="invalid-feedback d-block">
                                {{ form.keywords.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.length.id_for_label }}" class="form-label">故事长度</label>
                            {{ form.length }}
                            {% if form.length.errors %}
                            <div class="invalid-feedback d-block">
                                {{ form.length.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.style.id_for_label }}" class="form-label">写作风格</label>
                            {{ form.style }}
                            {% if form.style.errors %}
                            <div class="invalid-feedback d-block">
                                {{ form.style.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-robot me-2"></i>启动AI生成故事
                            </button>
                            <a href="{% url 'story:list' %}" class="btn btn-outline-secondary">取消</a>
                        </div>
                    </form>
                </div>
            </div>

            {% if generated_story %}
            <div class="card mt-4">
                <div class="card-header">
                    <h3 class="card-title mb-0">生成的故事</h3>
                </div>
                <div class="card-body">
                    <h4>{{ generated_story.title }}</h4>
                    <div class="story-content">
                        {{ generated_story.content|safe }}
                    </div>
                    <div class="mt-3">
                        <form method="post" action="{% url 'story:save_generated' %}">
                            {% csrf_token %}
                            <input type="hidden" name="title" value="{{ generated_story.title }}">
                            <input type="hidden" name="content" value="{{ generated_story.content }}">
                            <input type="hidden" name="category" value="{{ selected_category_id|default:'' }}">
                            <input type="hidden" name="category_name" value="{{ selected_category_name|default:'' }}">
                            <input type="hidden" name="keywords" value="{{ generated_story.keywords }}">
                            <button type="submit" class="btn btn-success">保存故事</button>
                        </form>
                    </div>
                </div>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %} 